<template>
	<view class="login">
		<view class="head">
			<text class="title">汽车租赁平台</text>
			<text class="sub-title">Hezhou mine into car rental platform</text>
		</view>
		
		<view class="sub-title2">
			<text>汽车租赁平台PC端 登录确认</text>
		</view>
		
		
		<view class="btn1 ">
			<button @click="login">立即登录</button>
		</view>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	export default {
		data() {
			return {
				token_code: ''
			};
		},
		computed:{
			...mapState('common', ['appid'])
		},
		onLoad(options) {
			console.log('验证登录', options);
			this.token_code = options.scene
		},
		methods:{
			async login() {
				const { code } = await uni.login({ provider: 'weixin' })
				
				const params = {
					appid: this.appid,
					code,
					token_code: this.token_code
				}
				this.$api.checkLoginApi(params).then(res=>{
					this.$store.commit('login/SET_TOKEN', res.data.access_token)
					this.$store.commit('login/SET_LOGIN_DATA', res.data)
					uni.showToast({
						title: res.retmsg 
					})
					setTimeout(()=>{
						if (res.data.login_verify === 1) {
							uni.reLaunch({
								url: '/pages/index/index'
							})
						} else {
							uni.redirectTo({
								url: '/pages/bind-phone/bind-phone'
							})
						}
					}, 1200)
				}).catch(err=>{
					console.log(err);
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.login{
	padding: 48rpx;
	
	.head{
		padding: 220rpx 0 0;
		display: flex;
		align-items: center;
		flex-direction: column;
	}
	
	.title{
		display: block;
		color: #000000;
		font-weight: 600;
		font-size: 44rpx;
		line-height: 62rpx;
	}
	
	.sub-title{
		display: block;
		color: #000000;
		font-weight: 300;
		font-size: 22rpx;
		line-height: 30rpx;
	}
	
	.sub-title2{
		display: block;
		color: #000000;
		font-size: 44rpx;
		line-height: 62rpx;
		text-align: center;
		padding-top: 32px;
		padding-bottom: 140px;
	}
	
	.form-item{
		width: 100%;
		height: 92rpx;
		border-radius: 8rpx;
		margin-bottom: 48rpx;
		background-color: #FFFFFF;
		border: 1px solid #F0F0F0;
	}
	
	.icon{
		width: 64rpx;
		height: 64rpx;
		text-align: center;
		line-height: 64rpx;
	}
	
	.f-input{
		width: 100%;
		border-radius: 8rpx;
	}
	
	button{
		width: 100%;
		height: 92rpx;
		line-height: 92rpx;
		border: none;
		&::after{
			border: none;
		}
	}
	.btn1{
		
		button{
			color: #FFFFFF;
			font-weight: 400;
			font-size: 34rpx;
			background-color: var(--primary-color);
		}
	}
	
	.btn2{
		
		button{
			font-weight: 400;
			font-size: 34rpx;
			color: var(--primary-color);
			background-color: transparent;
		}
	}
}
</style>
